from sqlalchemy import Column, Integer, String, BigInteger, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from config.database import Base
from datetime import datetime

class BaBusiness(Base):
    """
    营业记录表
    """

    __tablename__ = 'ba_business_records'

    id = Column(Integer, primary_key=True, autoincrement=True, comment='ID')
    m_id = Column(Integer, ForeignKey('ba_machine.id'), nullable=True, default=None, comment='机台ID')
    CurTimel = Column(DateTime, nullable=True, default=None, comment='客户端上传时间')
    TotalInNum = Column(Integer, nullable=True, default=None, comment='总进分数')
    TotalOutNum = Column(Integer, nullable=True, default=None, comment='总退分数')
    CurInOutBFB = Column(String(8), nullable=True, default=None, comment='进退金额百分比')
    TotalPlayFNum = Column(String(20), nullable=True, default=None, comment='总玩金额')
    TotalWinFNum = Column(String(20), nullable=True, default=None, comment='总赢金额')
    CurPlayOrWinBFB = Column(String(8), nullable=True, default=None, comment='总玩金额与总赢金额百分比')
    TotalPlayCNum = Column(Integer, nullable=True, default=None, comment='总玩次数')
    TotalWinCNum = Column(Integer, nullable=True, default=None, comment='总赢次数')
    CurPlayCountOrWinCount = Column(String(8), nullable=True, default=None, comment='总玩次数与总赢次数百分比')
    LastTimel = Column(DateTime, nullable=True, default=None, comment='上期记录时间')
    LastTotalInNum = Column(Integer, nullable=True, default=None, comment='上期总进分数')
    LastTotalOutNum = Column(Integer, nullable=True, default=None, comment='上期总退分数')
    LastInOutBFB = Column(String(8), nullable=True, default=None, comment='上期进退分数百分比')
    LastTotalPlayFNum = Column(Integer, nullable=True, default=None, comment='上期总玩分数')
    LastTotalWinFNum = Column(Integer, nullable=True, default=None, comment='上期总赢分数')
    LastPlayOrWinBFB = Column(String(8), nullable=True, default=None, comment='上期总赢分数总玩分数百分比')
    LastTotalPlayCNum = Column(Integer, nullable=True, default=None, comment='上期总玩次数')
    LastTotalWinCNum = Column(Integer, nullable=True, default=None, comment='上期总赢次数')
    LastTotalWinOrPlayCNum = Column(String(8), nullable=True, default=None, comment='上期总玩次数总赢次数百分比')
    add_time = Column(BigInteger, nullable=True, default=datetime.now().timestamp(), comment='创建时间')

    machine = relationship("BaMachine", 
                         back_populates="bussiness",
                         foreign_keys=[m_id])